<?php

/**
 * @fileoverview    美啦用户修改密码
 * @author          zhanglei11
 * @date            Thu Jan 05 14:34:25 CST 2012
 * @copyright       sina meila
 */

include_once '../../__global.php';

class aj_setPwd extends ml_controller{
    private $pwd;
    private $pwd_old;
//    private $pwd_confirm;
    

    function initParam() {
        $this->pwd_old = $this->input('pwd_old','P');            //老密码        
        $this->pwd = $this->input('pwd','P');                    //密码
        
    }
    
    function main() {

        
        // 获取当前登录用户 id
        $session = self::getSession();
        
        $uid = $session->getVal('uid');
        
        $oAccount = new ml_model_dbUserAccount();
        
        //获取用户信息        
        $rs = $oAccount->getAccountById($uid);
        $accountInfo = $oAccount->get_data();
        
        //如果老密码不相等
        $rs_compare = $oAccount->comparePwd($accountInfo['password'],$this->pwd_old);
        
        if(!$rs_compare) {
            $this->api_output(ML_RCODE_PARAM);
        }
        
        
        $rs = $oAccount->updatePwd($uid,$this->pwd);
        
        if($rs) { //  成功
            $this->api_output(ML_RCODE_SUCC);
           // $this->set_scope_var('$notice',"");
        }else {   //  修改密码失败
            $this->api_output(ML_RCODE_FAIL);
        }
    }



    function checkParam(){
        $this->check_referer();
//        $this->pwd_confirm = $this->input('pwd_confirm');    //确认密码
        
    }

}

new aj_setPwd();

